import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";
import { getToken } from "@/utils/auth";

export const getMapJson = (code: string) => {
  return http.request("get", baseUrlApi("idp/static/map/" + code));
};

export const getIdpOrgList = () => {
  return http.request<any[]>("get", baseUrlApi("org/GetOrgList"));
};

export const uploadOfficePic = (option: any) => {
  console.log(option);
  if (typeof option != "undefined") {
    const formData = new FormData();
    formData.append("pic", option.file);
    formData.append("hcy", "hcy");
    console.log(formData);
    console.log(formData.get("pic"));
    return http.request<string>(
      "post",
      baseUrlApi("org/SavePlantPic"),
      {
        data: formData
      },
      {
        headers: {
          "Content-Type": "multipart/form-data"
        }
      }
    );
  }
};

export const getUploadOfficePicUrl = () => {
  return baseUrlApi("");
};

export const getHeader = () => {
  return {
    Authorization: "Bearer " + getToken().accessToken,
    "Content-Type": "multipart/form-data"
  };
};

export const getDeviceList = (id: string) => {
  return http.request<any[]>("get", baseUrlApi("org/devices/" + id));
};

export const savePoint = (data: any) => {
  return http.request("post", baseUrlApi("org/SavePoint"), { data });
};

export const getPoint = (id: string) => {
  return http.request("get", baseUrlApi("org/GetPoint/" + id));
};
